const app = new Vue({
    el: '#app',
    data: {
        list: [
            {
                id: 1,
                name: '大话东游',
                date: '2002-02-02',
                price: 85.00,
                count: 1
            },
            {
                id: 1,
                name: '大话西游',
                date: '2202-02-02',
                price: 408.22,
                count: 2
            },
            {
                id: 1,
                name: '大话南游',
                date: '2102-02-02',
                price: 39.00,
                count: 3
            },
            {
                id: 1,
                name: '游mm呢',
                date: '2002-02-02',
                price: 200.00,
                count: 3
            },
        ],
        currentIndex: 0,
    },
    // 定义过滤器，保留数字为两位有效数字
    filters: {
        showPrice(price) {
            return '￥' + price.toFixed(2);
        }
    },
    methods: {
        increment(index) {
            this.list[index].count++;
        },
        decrease(index) {
            this.list[index].count--;
        },
        remove(index) {
            this.list.splice(index, 1);
        }
    },
    computed: {
        totalPrice() {
            let totalPrice = 0;
            for (let book of this.list) {
                totalPrice+=book.count*book.price;
            }
            return totalPrice;
        }
    }
})